﻿using Google.Protobuf;
using Server.Framework.Message;
using Server.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Message.Response
{
    /// <summary>
    /// Author: Leil
    /// Description: 组织列表回复消息
    /// CreateTime: 2020/5/13 12:31:32
    /// </summary>
    class OrgListResp : ResponseBaseMessage
    {
        public List<OrgDao> Orgs { get; } = new List<OrgDao>();

        public int Count { get; set; }

        public OrgListResp(int msgId):base(msgId)
        {

        }

        public override byte[] Serialize()
        {
            OrgList msg = new OrgList();
            Orgs.ForEach(org =>
            {
                Org o = new Org
                {
                    Id = org.ID,
                    ParentId = org.ParentId,
                    OrgName = org.OrgName ?? "",
                    Sort = org.Sort,
                    Status = org.Status,
                    Creator = org.Creator ?? "",
                    CreateTime = org.CreateTime ?? "",
                    Updator = org.Updator ?? "",
                    UpdateTime = org.UpdateTime ?? "",
                };
                msg.Orgs.Add(o);
            });
            msg.Count = Count;
            return msg.ToByteArray();
        }
    }
}
